﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;

namespace UniMana.Data
{
    public static class Log_AddStudentSubjectClassData
    {
        public static IQueryable GetTop1(this Table<Log_AddStudentSubjectClass> tLogAdd)
        {
            var l = (from log in tLogAdd
                     orderby log.Log_AddStudentSubjectClassKey descending
                     select log).Take(1);
            return l;
        }
        public static IQueryable GetList(this Table<Log_AddStudentSubjectClass> tLogAdd, Table<Personnel_Personnel> tPersonel,
                                         Table<Training_Student> tStudent, Table<Training_Subject_Class> tSubjectClass,
                                            Table<Training_Student_Class> tStudentClass)
        {
            var l = from logAdd in tLogAdd
                    from personel in tPersonel
                    from student in tStudent
                    from subjectClass in tSubjectClass
                    from studentClass in tStudentClass

                    where logAdd.PersonelRequiredKey == personel.Personnel_PersonnelKey
                    where student.Training_StudentKey == logAdd.Training_StudentKey
                    where subjectClass.Training_Subject_ClassKey == logAdd.Training_Subject_ClassKey
                    where studentClass.Training_StudentKey == logAdd.Training_StudentKey

                    orderby logAdd.Log_AddStudentSubjectClassKey descending
                    select new
                    {
                        logAdd.Log_AddStudentSubjectClassKey,
                        logAddID = logAdd.ID,
                        logAdd.DateCensorship,
                        logAdd.DateCreate,
                        logAdd.Feedback,
                        logAdd.Permit,
                        logAdd.PersonelCensorshipKey,
                        logAdd.PersonelRequiredKey,
                        logAdd.Reason,
                        logAdd.Refuse,
                        logAdd.Status,
                        logAdd.StudentID,
                        logAdd.Training_StudentKey,
                        logAdd.Training_Subject_ClassKey,
                        studentName = student.LastName + " "+ student.SureName,
                        student.Birthday,
                        student.Gender,
                        personelName = personel.LastName + " "+ personel.Name,
                        subjectClassName = subjectClass.Name,
                        subjectClassID = subjectClass.ID,
                        studentClass.Training_TrainingProgramKey
                    };
            return l;
        }
    }
}
